/**
 * 
 */
package leetCode;

/**
 * @author zhong
 *
 */
public class PairsofSongsWithTotalDurationsDivisibleby60 {
	public int numPairsDivisibleBy60(int[] time) {
		int n = time.length;
		int[] count_mod = new int[60];
		for (int i = 0; i < time.length; i++) {
			count_mod[time[i] % 60]++;
		}
		int res = 0;
		for (int i = 1; i < 30; i++) {
			res += count_mod[i] * count_mod[60 - i];
		}
		res += count_mod[0] * (count_mod[0] - 1) / 2;
		res += count_mod[30] * (count_mod[30] - 1) / 2;
		return res;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] res = { 30, 20, 150, 100, 40 };
		PairsofSongsWithTotalDurationsDivisibleby60 pairsofSongsWithTotalDurationsDivisibleby60 = new PairsofSongsWithTotalDurationsDivisibleby60();
		System.out.println(pairsofSongsWithTotalDurationsDivisibleby60.numPairsDivisibleBy60(res));
	}

}
